package com.ly.hotel.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.model.WeatherCity;
import com.ly.hotel.model.WeatherProvince;
import com.ly.hotel.view.InitActivity;
import com.ly.hotel.view.setting.SystemSettingActivity;

import java.util.List;

/**
 * Created by SHUBEN on 2018/4/3.
 */

public class ProvinceDialog extends Dialog {
    private SystemSettingActivity mcontext;
    private List<WeatherProvince> weatherProvinces;
    private ListView mListView;

    public ProvinceDialog(SystemSettingActivity context, int theme,List<WeatherProvince> weatherProvinces) {
        super(context, theme);
        mcontext = context;
        this.weatherProvinces = weatherProvinces;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_provice);
        mListView = findViewById(R.id.areaSelectList);
        mListView.setAdapter(new proAdapter(mcontext));
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                List<WeatherCity> weatherCities = weatherProvinces.get(position).getWeatherCities();
                mcontext.showCityDialog(weatherCities);
                dismiss();
            }
        });
    }

    class proAdapter extends BaseAdapter{
        private LayoutInflater mInflater;

        public proAdapter(Context c) {
            mInflater = LayoutInflater.from(c);
        }

        @Override
        public int getCount() {
            return weatherProvinces.size();
        }

        @Override
        public Object getItem(int postion) {
            return weatherProvinces.get(postion);
        }

        @Override
        public long getItemId(int postion) {
            return postion;
        }

        @Override
        public View getView(int position, View contentView, ViewGroup arg2) {
            final int pos = position;
            ViewHolder holder;

            if (contentView == null) {

                holder = new ViewHolder();
                contentView = mInflater.inflate(R.layout.vod_btn_item, null);
                holder.mbtn = contentView.findViewById(R.id.m_vod_item_btn);
                contentView.setTag(holder);
            } else {
                holder = (ViewHolder) contentView.getTag();
            }
            holder.mbtn.setTextColor(Color.parseColor("#333333"));
            holder.mbtn.setText(weatherProvinces.get(position).getName());
            return contentView;
        }

        class ViewHolder {
            TextView mbtn;
        }
    }
}
